﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true"
    CodeBehind="AdminCategories.aspx.cs" Inherits="FlowersStore.AdminCategories" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <h2 class="AdminPart">
            Категории</h2>
    </div>
    <div>
        <asp:Label class="AdminSubPart" Text="Раздел:" runat="server" />
        <asp:DropDownList ID="ddlDapartments" runat="server" AutoPostBack="True" DataSourceID="DepartmentsSqlDataSource"
            DataTextField="Department_name" DataValueField="Department_id" OnSelectedIndexChanged="ddlDapartments_SelectedIndexChanged" />
        <asp:SqlDataSource ID="DepartmentsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:FlowerStoreConnectionString %>"
            SelectCommand="SELECT [Department_name], [Department_id] FROM [Department]">
        </asp:SqlDataSource>
        <asp:LinqDataSource ID="CategoriesLinqDataSource" runat="server" ContextTypeName="FlowersStore.FlowerStoreDataContext"
            EnableDelete="True" EnableInsert="True" EnableUpdate="True" EntityTypeName=""
            TableName="Categories" Where="Department_id == @Department_id">
            <WhereParameters>
                <asp:ControlParameter ControlID="ddlDapartments" Name="Department_id" PropertyName="SelectedValue"
                    Type="Int64" />
            </WhereParameters>
        </asp:LinqDataSource>
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="Category_id" DataSourceID="CategoriesLinqDataSource"
            InsertItemPosition="LastItem" OnItemInserting="ListView1_ItemInserting" OnItemUpdating="ListView1_ItemUpdating">
            <AlternatingItemTemplate>
                <tr style="background-color: #FFF8DC;">                   
                    <td>
                        <asp:Label ID="Category_nameLabel" runat="server" Text='<%# Eval("Category_name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="Category_descriptionLabel" runat="server" Text='<%# Eval("Category_description") %>' />
                    </td>
                    <td>
                        <asp:Label ID="Category_departmentName" runat="server" Text='<%# Eval("Department.Department_name") %>' />
                    </td>
                    <td>
                        <asp:HyperLink ID="HyperLink1" runat="server" Text="Редактировать товары" NavigateUrl='<%# "AdminProducts.aspx?cat="+Eval("Category_id")  %>' />
                    </td>
                     <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Удалить" />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Редактировать" />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <tr style="background-color: #008A8C; color: #FFFFFF;">                    
                    <td>
                        <asp:TextBox ID="Category_nameTextBox" runat="server" Text='<%# Bind("Category_name") %>' />
                        <asp:RequiredFieldValidator ID="editValidator" runat="server" ControlToValidate="Category_nameTextBox"
                            ValidationGroup="editValidation" ErrorMessage="*" Display="Dynamic" />
                    </td>
                    <td>
                        <asp:TextBox ID="Category_descriptionTextBox" runat="server" Text='<%# Bind("Category_description") %>' />
                    </td>
                    <td>
                        <asp:DropDownList ID="departments" runat="server" AppendDataBoundItems="true" DataSourceID="DepartmentsSqlDataSource"
                            DataTextField="Department_name" DataValueField="Department_id" />
                    </td>
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Изменить"
                            CausesValidation="true" ValidationGroup="editValidation" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Отмена" CausesValidation="false" />
                    </td>
                </tr>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                    border-color: #999999; border-style: none; border-width: 1px;">
                    <tr>
                        <td>
                            Таблица пуста.
                        </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr style="">                    
                    <td>
                        <asp:TextBox ID="Category_nameTextBox" runat="server" Text='<%# Bind("Category_name") %>' />
                        <asp:RequiredFieldValidator runat="server" ID="insertValidator" ControlToValidate="Category_nameTextBox"
                            ValidationGroup="insertValidation" ErrorMessage="*" Display="Dynamic" />
                    </td>
                    <td>
                        <asp:TextBox ID="Category_descriptionTextBox" runat="server" Text='<%# Bind("Category_description") %>' />
                    </td>
                    <td>
                        <asp:DropDownList ID="departments" runat="server" AppendDataBoundItems="true" DataSourceID="DepartmentsSqlDataSource"
                            DataTextField="Department_name" DataValueField="Department_id" />
                    </td>
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Создать"
                            CausesValidation="true" ValidationGroup="insertValidation" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" CausesValidation="false"
                            Text="Очистить" />
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr style="background-color: #DCDCDC; color: #000000;">                    
                    <td class="AdminTabCell">
                        <asp:Label ID="Category_nameLabel" runat="server" Text='<%# Eval("Category_name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="Category_descriptionLabel" runat="server" Text='<%# Eval("Category_description") %>' />
                    </td>
                    <td class="AdminTabCell">
                        <asp:Label ID="Category_departmentName" runat="server" Text='<%# Eval("Department.Department_name") %>' />
                    </td>
                    <td class="AdminTabCell">
                        <asp:HyperLink runat="server" Text="Редактировать товары" NavigateUrl='<%# "AdminProducts.aspx?cat="+Eval("Category_id")  %>' />
                    </td>
                    <td class="AdminTabCell">
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Удалить" />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Редактировать" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table class="AdminTable" id="itemPlaceholderContainer" runat="server" border="1"
                                style="background-color: #FFFFFF; border-collapse: collapse; border-color: #999999;
                                border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
                                <tr runat="server" style="background-color: #DCDCDC; color: #000000;">                                    
                                    <th class="AdminTabTopLineCell" runat="server">
                                        Категория
                                    </th>
                                    <th class="AdminTabTopLineCell" runat="server">
                                        Описание
                                    </th>
                                    <th class="AdminTabTopLineCell" runat="server">
                                        Раздел
                                    </th>
                                    <th class="AdminTabTopLineCell" id="Th1" runat="server">
                                        Товары
                                    </th>
                                    <th id="Th2" class="AdminTabTopLineCell" runat="server">
                                    </th>
                                </tr>
                                <tr id="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr runat="server">
                        <td runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                            color: #000000;">
                            <asp:DataPager ID="DataPager1" runat="server">
                                <Fields>
                                    <asp:NumericPagerField ButtonType="Link" />
                                </Fields>
                            </asp:DataPager>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
        </asp:ListView>
        <br />
    </div>
</asp:Content>
